//
//  ResumeCenterCtrl.m
//  laowu
//
//  Created by Northwan on 15/5/2.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "ResumeCenterCtrl.h"
#import "HomeDataTool.h"
#import "ResumeModifyCtrl.h"

@interface ResumeCenterCtrl ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIImageView *headImgView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *idCardLabel;
@property (weak, nonatomic) IBOutlet UILabel *telLabel;
@property (weak, nonatomic) IBOutlet UILabel *workTypeLabel;
@property (weak, nonatomic) IBOutlet UILabel *levelLabel;
@property (weak, nonatomic) IBOutlet UILabel *salaryLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;

@property (weak, nonatomic) IBOutlet UIButton *enterBtn;
@property(strong,nonatomic)ResumeRes *result;
@end

@implementation ResumeCenterCtrl


-(instancetype)initWithResumeRes:(ResumeRes *)resumeRes
{
    self = [super init];
    if (self) {
        self.result = resumeRes;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setTitle:@"求职简历"];
    CALayer *layer=[self.headImgView layer];
    [layer setCornerRadius:self.headImgView.width/2];
    [layer setMasksToBounds:YES];
    [layer setBorderWidth:2];
    [layer setBorderColor:[[UIColor whiteColor] CGColor]];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(modifyResumeSuccess:) name:@"notif_modify_resume_success" object:nil];
    
    if (self.result) {
        [self.enterBtn setHidden:YES];
    }
}

-(void)modifyResumeSuccess:(NSNotification*)notif{
    [self getData];
}

-(void)viewWillAppear:(BOOL)animated{
    if(!_result)
     [self getData];
    else
     [self initData];
}

-(void)getData{
    MBProgressHUD *lodingView =  [DialogUtils showLoadingWithView:self.view];
    [HomeDataTool getResumeInfo:^(ResumeRes *result) {
        [lodingView hide:YES];
        if(result.isSucc){
            _result = result;
            [self initData];
        }else{
            [DialogUtils showTipsWithView:self.view String:result.msg];
        }
    } failure:^(NSError *error) {
        [lodingView hide:YES];
         [DialogUtils showTipsWithView:self.view String:@"加载失败"];
    }];
}

-(void)initData{
    [_headImgView sd_setImageWithURL:[NSURL URLWithString:_result.head_img_url] placeholderImage:[UIImage imageNamed:@"headavatar"]];
    [_nameLabel setText:_result.user_name];
    [_idCardLabel setText:_result.identity_card];
    [_telLabel setText:_result.telnum];
    [_workTypeLabel setText:_result.work_type];
    [_levelLabel setText:_result.work_skill_level];
    [_salaryLabel setText:_result.salary];
    [_addressLabel setText:[NSString stringWithFormat:@"%@ %@",_result.province,_result.city]];
}

- (IBAction)tapModifyProfileAction:(id)sender {
    ResumeModifyCtrl *ctrl = [ResumeModifyCtrl initWithData:_result];
    [self.navigationController pushViewController:ctrl animated:YES];
    NSLog(@"修改简历");
}



-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

@end
